import * as api from './dd_api';

const BASE_URL = 'https://api.dingtalk.com';
const AGENT_ID = '4009736782';

/**
 * 获取企业内部应用 AccessToken
 */
export async function getDdAccessToken() {
  return new Promise((resolve, reject) => {
    my.httpRequest({
      url: `${BASE_URL}${api.getDdAccessToken}`,
      method: 'POST',
      data: JSON.stringify({
        appKey: 'dingjq1c48qb0yxzp6fd',
        appSecret: '_V0OV2M0nw6LhtWrcebWrVvaavO-xNgn8R09M57u_I8MJJY8kGk14xUHTICJuiOP'
      }),
      headers: {
        'Content-Type': 'application/json'
      },
      success: res => resolve(res),
      fail: reject
    });
  });
}

/**
 * 获取小程序版本列表（需传入上一步拿到的 token）
 */
export async function getDdInnerMiniAppsVersions(token = '') {
  return new Promise((resolve, reject) => {
    my.httpRequest({
      url: `${BASE_URL}${api.getDdInnerMiniAppsVersions}`,
      method: 'GET',
      data: {
        agentId: AGENT_ID
      },
      headers: {
        'Content-Type': 'application/json',
        'x-acs-dingtalk-access-token': token
      },
      success: res => resolve(res),
      fail: reject
    });
  });
}